Completed
Pull Request — master (#94)
by Maxence
02:28
created

actions.changeLinkStatus   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: resultMembers */
34
/** global: resultGroups */
35
/** global: resultCircles */
36
/** global: curr */
37
/** global: api */
38
/** global: define */
39
/** global: resultLinks */
40
/** global: settings */
41
42
43
var actions = {
44
45
46
	changeMemberLevel: function (member, level) {
47
		if (parseInt(level) === define.levelOwner) {
48
			actions.changeMemberOwner(member);
49
			return;
50
		}
51
		api.levelMember(curr.circle, member, level, resultMembers.levelMemberResult);
52
		nav.circlesActionReturn();
53
	},
54
55
56
	changeGroupLevel: function (group, level) {
57
58
		if (level === 'remove_group') {
59
			api.unlinkGroup(curr.circle, group, resultGroups.unlinkGroupResult);
60
		} else {
61
			api.levelGroup(curr.circle, group, level, resultGroups.levelGroupResult);
62
		}
63
		nav.circlesActionReturn();
64
	},
65
66
67
	changeMemberOwner: function (member) {
68
		OC.dialogs.confirm(
69
			t('circles', 'Are you sure you want to transfer your Owner rights ?', [member]),
70
			t('circles', 'This action is irreversible'),
71
			function (e) {
72
				if (e === true) {
73
					api.levelMember(curr.circle, member, define.levelOwner,
74
						resultMembers.levelMemberResult);
75
					nav.circlesActionReturn();
76
					return;
77
				}
78
79
				nav.displayMembers('');
80
			});
81
	},
82
83
84
	changeMemberStatus: function (member, value) {
85
		if (value === 'remove_member' || value === 'dismiss_request') {
86
			api.removeMember(curr.circle, member, resultMembers.removeMemberResult);
87
		}
88
		if (value === 'accept_request') {
89
			api.addMember(curr.circle, member, resultMembers.addMemberResult);
90
		}
91
	},
92
93
94
	changeLinkStatus: function (link, value) {
95
		api.linkStatus(link, value, resultLinks.linkStatusResult);
96
	},
97
98
99
	selectCircle: function (circle_id) {
100
		curr.searchUser = '';
101
		elements.addMember.val('');
102
		elements.linkGroup.val('');
103
		elements.linkCircle.val('');
104
105
		nav.circlesActionReturn();
106
		api.detailsCircle(circle_id, resultCircles.selectCircleResult);
107
	},
108
109
110
	unselectCircle: function (circle_id) {
111
		elements.mainUIMembersTable.emptyTable();
112
		elements.navigation.children(".circle[circle-id='" + circle_id + "']").remove();
113
		elements.emptyContent.show(800);
114
		elements.mainUI.fadeOut(800);
115
116
		curr.circle = 0;
117
		curr.circleLevel = 0;
118
	},
119
120
121
	saveSettings: function () {
122
		data = {
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
123
			circle_name: elements.settingsName.val(),
124
			circle_desc: elements.settingsDesc.val(),
125
			allow_links: (elements.settingsLink.is(":checked")),
126
			allow_links_auto: (elements.settingsLinkAuto.is(":checked")),
127
			allow_links_files: (elements.settingsLinkFiles.is(":checked"))
128
		};
129
130
		api.settingsCircle(curr.circle, data, settings.saveSettingsResult);
131
	},
132
133
	/**
134
	 *
135
	 * @param search
136
	 */
137
	searchMembersRequest: function (search) {
138
139
		if (curr.searchUser === search) {
140
			return;
141
		}
142
143
		curr.searchUser = search;
144
145
		$.get(OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees',
146
			{
147
				format: 'json',
148
				search: search,
149
				perPage: 200,
150
				itemType: 'principals'
151
			}, resultMembers.searchMembersResult);
152
	},
153
154
155
	/**
156
	 *
157
	 * @param search
158
	 */
159
	searchGroupsRequest: function (search) {
160
161
		if (curr.searchGroup === search) {
162
			return;
163
		}
164
165
		curr.searchGroup = search;
166
167
		$.get(OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees',
168
			{
169
				format: 'json',
170
				search: search,
171
				perPage: 200,
172
				itemType: 'principals'
173
			}, resultGroups.searchGroupsResult);
174
	},
175
176
177
	getStringTypeFromType: function (type) {
178
		switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
179
			case '1':
180
				return t('circles', 'Personal circle');
181
			case '2':
182
				return t('circles', 'Hidden circle');
183
			case '4':
184
				return t('circles', 'Private circle');
185
			case '8':
186
				return t('circles', 'Public circle');
187
		}
188
189
		return t('circles', 'Circle');
190
	},
191
192
193
	/**
194
	 *
195
	 */
196
	onEventNewCircle: function () {
197
		curr.circle = 0;
198
		curr.circleLevel = 0;
199
200
		elements.circlesList.children('div').removeClass('selected');
201
		elements.emptyContent.show(800);
202
		elements.mainUI.fadeOut(800);
203
	},
204
205
206
	/**
207
	 *
208
	 */
209
	onEventNewCircleName: function () {
210
		this.onEventNewCircle();
211
		nav.displayOptionsNewCircle((elements.newName.val() !== ''));
212
	},
213
214
215
	/**
216
	 *
217
	 */
218
	onEventNewCircleType: function () {
219
		this.onEventNewCircle();
220
		elements.newTypeDefinition.children('div').fadeOut(300);
221
		var selectedType = elements.newType.children('option:selected').val();
222
		if (selectedType === '') {
223
			elements.newType.addClass('select_none');
224
		}
225
		else {
226
			elements.newType.removeClass('select_none');
227
			$('#circles_new_type_' + selectedType).fadeIn(
228
				300);
229
		}
230
	}
231
232
233
};
234